/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf;

import ejb.CompraFacade;
import entity.Compra;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author mbvierci
 */
@ManagedBean
@RequestScoped
public class CompraBean {
    
    @EJB
    private CompraFacade compraFacade;
    private Compra compra = new Compra();
    private List<Compra> compras;

    /**
     * Creates a new instance of CompraBean
     */
    public CompraBean() {
    }
    
     public Compra getCompra() {
        return compra;
    }

    public void setCompra(Compra compra) {
        this.compra = compra;
    }
    
    public CompraFacade getCompraFacade() {
        return compraFacade;
    }

    public void setCompraFacade(CompraFacade compraFacade) {
        this.compraFacade = compraFacade;
        compras = compraFacade.findAll();
    }

    public List<Compra> getCompras() {
        return compras;
    }

    public void setCompras(List<Compra> compras) {
        this.compras = compras;
    }
    
    public void crearCompra(){
        compraFacade.create(compra);
        compras.add(compra);
        compra = new Compra();
    }
}
